﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.ServiceModel.Description;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using ServidorActividad;
using Eventos;
using System.Threading;

namespace ServidorConciliacion
{
    public class Program
    {
        static void Main(string[] args)
        {
            //Inicializacion de variables
            String IPLocal = ConfigurationManager.AppSettings["IP_LOCAL"];
            String PuertoLocal = ConfigurationManager.AppSettings["PUERTO_LOCAL"];
            String NombreServicioWCF = ConfigurationManager.AppSettings["NOMBRE_SERVICIO_WCF"];


            ServiceHost studentServiceHost = null;
            try {


                //Base Address for StudentService
                Uri httpBaseAddress = new Uri("http://"+IPLocal + ":" + PuertoLocal + "/" + NombreServicioWCF);

                //Instantiate ServiceHost
                studentServiceHost = new ServiceHost(typeof(ServidorConciliacion.ConciliacionWCF),
                    httpBaseAddress);

                //Add Endpoint to Host
                studentServiceHost.AddServiceEndpoint(typeof(ServidorConciliacion.IConciliacionWCF),
                                                        new WSHttpBinding(),"");

                //Metadata Exchange
                ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior();
                serviceBehavior.HttpGetEnabled = true;
                studentServiceHost.Description.Behaviors.Add(serviceBehavior);

                //Open
                studentServiceHost.Open();
                Console.WriteLine("Servidor Conciliacion Iniciado: {0}", httpBaseAddress);
                Console.ReadKey();
            } catch (Exception ex) {
                studentServiceHost = null;
                Console.WriteLine("No se pudo iniciar el servidor de conciliacion" +ex.Message);
                Console.ReadKey();
            }
        
        }

    }
}
